home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Santa.lua < prev    next >
Text File  |  2010-08-31  |  7KB  |  197 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Santa + Projectile Santa + Projectile Gift
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.santa={}
  10. cc.santa.santa={}
  11. cc.santa.gift={}
  12.  
  13. -- Load & Prepare Ressources
  14. cc.santa.gfx_wpn=loadgfx("weapons/santa.bmp")                    -- Weapon Image
  15. setmidhandle(cc.santa.gfx_wpn)
  16. cc.santa.gfx_sleigh0=loadgfx("weapons/santa0.bmp")                -- Sleigh Frame 1
  17. setmidhandle(cc.santa.gfx_sleigh0)
  18. cc.santa.gfx_sleigh1=loadgfx("weapons/santa1.bmp")                -- Sleigh Frame 2
  19. setmidhandle(cc.santa.gfx_sleigh1)
  20. cc.santa.gfx_gift=loadgfx("weapons/gift.bmp")                    -- Gift
  21. setmidhandle(cc.santa.gfx_gift)
  22. cc.santa.sfx_hohoho=loadsfx("hohoho.ogg")                        -- HoHoHo Sound
  23. cc.santa.sfx_throw=loadsfx("throw.ogg")                            -- Throw Sound
  24. cc.santa.sfx_bounce=loadsfx("bounce.wav")                        -- Bounce Sound
  25.  
  26. --------------------------------------------------------------------------------
  27. -- Weapon: Santa
  28. --------------------------------------------------------------------------------
  29.  
  30. cc.santa.id=addweapon("cc.santa","Santa",cc.santa.gfx_wpn,0,2)    -- Add Weapon (0 uses, first in round 2)
  31.  
  32. function cc.santa.draw()                                        -- Draw
  33.     -- Do nothing
  34. end
  35.  
  36. function cc.santa.attack(attack)                                -- Attack
  37.     if (weapon_shots<=0) then
  38.         if attack==1 then
  39.             -- No more weapon switching!
  40.             useweapon(0)
  41.             playsound(cc.santa.sfx_hohoho)
  42.             weapon_shots=weapon_shots+1
  43.             id=createprojectile(cc.santa.santa.id)
  44.             projectiles[id]={}
  45.             -- Set initial position of projectile
  46.             projectiles[id].x=-100
  47.             projectiles[id].y=-150
  48.             -- End Turn
  49.             endturn()
  50.         end
  51.     end
  52. end
  53.  
  54. --------------------------------------------------------------------------------
  55. -- Projectile: Santa
  56. --------------------------------------------------------------------------------
  57.  
  58. cc.santa.santa.id=addprojectile("cc.santa.santa")            -- Add Projectile
  59.  
  60. function cc.santa.santa.draw(id)                            -- Draw
  61.     -- Setup draw mode
  62.     setblend(blend_alpha)
  63.     setalpha(1)
  64.     setcolor(255,255,255)
  65.     setscale(1,1)
  66.     setrotation(0)
  67.     -- Draw projectile
  68.     weapon_timer=weapon_timer+1
  69.     if weapon_timer>=10 then
  70.         weapon_timer=0
  71.         weapon_mode=1-weapon_mode
  72.     end
  73.     if weapon_mode==0 then
  74.         drawimage(cc.santa.gfx_sleigh0,projectiles[id].x,projectiles[id].y)
  75.     else
  76.         drawimage(cc.santa.gfx_sleigh1,projectiles[id].x,projectiles[id].y)
  77.     end
  78. end
  79.  
  80. function cc.santa.santa.update(id)                    -- Update
  81.     -- Particle Tail
  82.     particle(p_lightpuff,projectiles[id].x+50,projectiles[id].y+20)
  83.     particlespeed(math.random(-2,2)*0.1,math.random(-3,3)*0.1)
  84.     particlecolor(100,0,math.random(0,255))
  85.     particlefadealpha(0.01)
  86.     -- Move
  87.     projectiles[id].x=projectiles[id].x+5
  88.     -- In Drop Area?
  89.     if projectiles[id].x<=(getmapwidth()+100) then
  90.         -- Drop Stuff
  91.         if math.mod(projectiles[id].x,200)==0 then
  92.             -- Drop Gift
  93.             playsound(cc.santa.sfx_throw)
  94.             pid=createprojectile(cc.santa.gift.id)
  95.             projectiles[pid]={}
  96.             projectiles[pid].x=projectiles[id].x-30
  97.             projectiles[pid].y=projectiles[id].y
  98.             projectiles[pid].sx=0
  99.             projectiles[pid].sy=2
  100.             projectiles[pid].timer=5*50
  101.         elseif math.mod(projectiles[id].x,100)==0 then
  102.             -- Drop Supply
  103.             playsound(cc.santa.sfx_throw)
  104.             createobject(o_supply,projectiles[id].x-30,projectiles[id].y)
  105.         end
  106.         -- Scroll to projectile
  107.         scroll(projectiles[id].x,projectiles[id].y)
  108.     -- Free projectile
  109.     elseif projectiles[id].x>(getmapwidth()+500) then
  110.         -- Free projectile
  111.         freeprojectile(id)
  112.     end
  113. end
  114.  
  115. --------------------------------------------------------------------------------
  116. -- Projectile: Gift
  117. --------------------------------------------------------------------------------
  118.  
  119. cc.santa.gift.id=addprojectile("cc.santa.gift")                -- Add Projectile
  120.  
  121. function cc.santa.gift.draw(id)                                -- Draw
  122.     -- Setup draw mode
  123.     setblend(blend_alpha)
  124.     setalpha(1)
  125.     setcolor(255,255,255)
  126.     setscale(1,1)
  127.     setrotation(0)
  128.     -- Draw projectile
  129.     drawimage(cc.santa.gfx_gift,projectiles[id].x,projectiles[id].y)
  130.     -- Draw Arrow if out of Screen
  131.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  132. end
  133.  
  134. function cc.santa.gift.update(id)                            -- Update
  135.     -- Gravity influence on speed
  136.     projectiles[id].sy=projectiles[id].sy+getgravity()
  137.     -- Move (in substep loop for optimal collision precision)
  138.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/5)
  139.     msubx=projectiles[id].sx/msubt
  140.     msuby=projectiles[id].sy/msubt
  141.     for i=1,msubt,1 do
  142.         -- Move X
  143.         projectiles[id].x=projectiles[id].x+msubx
  144.         if collision(cc.santa.gfx_gift,projectiles[id].x,projectiles[id].y)==1 then
  145.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  146.                 if (math.abs(projectiles[id].sx)>0.5) then playsound(cc.santa.sfx_bounce) end
  147.                 projectiles[id].x=projectiles[id].x-msubx
  148.                 projectiles[id].sx=-projectiles[id].sx*0.05
  149.                 msubx=-msubx*0.05
  150.             end
  151.         else
  152.             projectiles[id].ignore=0
  153.         end
  154.         -- Move Y
  155.         projectiles[id].y=projectiles[id].y+msuby
  156.         if collision(cc.santa.gfx_gift,projectiles[id].x,projectiles[id].y)==1 then
  157.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  158.                 if (math.abs(projectiles[id].sy)>0.5) then playsound(cc.santa.sfx_bounce) end
  159.                 projectiles[id].y=projectiles[id].y-msuby
  160.                 projectiles[id].sy=-projectiles[id].sy*0.3
  161.                 msuby=-msuby*0.3
  162.             end
  163.         else
  164.             projectiles[id].ignore=0
  165.         end        
  166.         -- Water
  167.         if (projectiles[id].y)>getwatery()+5 then
  168.             -- Effects
  169.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  170.             playsound(sfx_hitwater1)
  171.             -- Free projectile
  172.             freeprojectile(id)
  173.             break
  174.         end
  175.     end
  176.     -- Timer -> Explode
  177.     projectiles[id].timer=projectiles[id].timer-1
  178.     if projectiles[id].timer<=0 then
  179.         -- Scroll to projectile
  180.         scroll(projectiles[id].x,projectiles[id].y)
  181.         -- Cause damage
  182.         arealdamage(projectiles[id].x,projectiles[id].y,125,65)
  183.         -- Destroy terrain
  184.         terrainexplosion(projectiles[id].x,projectiles[id].y,55,1)
  185.         -- Crater
  186.         grey=math.random(0,40)
  187.         if math.random(0,1)==1 then
  188.             terrainalphaimage(gfx_crater150,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  189.         else
  190.             terrainalphaimage(gfx_crater175,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  191.         end
  192.         stopchannel(0)
  193.         -- Free projectile
  194.         freeprojectile(id)
  195.     end
  196. end
  197.